import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ShoppingRequest extends HttpServlet
{
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
    	throws ServletException, IOException
     {
		 page1(req, res, req.getSession(false));
     }
	
	  protected void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
      {
		  if(req.getParameter("login") != null)
		  {
			  HttpSession session = req.getSession(true);
			  String username = req.getParameter("username");
			  String password = req.getParameter("password");
			  session.putValue("username", username);
			  session.putValue("password", password);
			  page1(req, res, session);
		  }
		  else
		  {
			  HttpSession session = req.getSession(false);
			  if(session != null) session.invalidate();
			  page1(req, res, null);
		  }
      }
	
	public void page1(HttpServletRequest req,HttpServletResponse res,HttpSession session)throws ServletException, IOException
	{
		PrintWriter out=res.getWriter();
		
		if(session == null)
		{
			out.println("<html><head><title>Shopping Cart - Login</title></head>" +
					"<body><form method=\"POST\">" +
					"<table>" +
					"<font face = 'Trebuchet MS'>"+
					"<tr>" +
					"<td>Enter your <b>USERNAME:</b>s</td><td><input type=text name=\"username\"></td>" +
					"</tr>" +
					"<tr>" +
					"<td>Enter your <b>PASSWORD</b></td><td><input type=password name=\"password\"></td>" +
					"</tr>" +
					"<tr>" +
					"<td><input type=submit name=login value=\"login\"></td>" +
					"</tr>" +
					"</font>"+
					"</table>" +
					"</form>");
		}
		else
		{
		
		out.println("<html><head><title>Sports Cart</title></head>" +
				"<body><form method=\"POST\" action=\"http://localhost:8080/ShoppingCart/AddCart\""
				+ "<h2>Welcome " + session.getValue("username") + "</h2>"
		+"<p><font size=\"5\">G3 Shopping Cart</font></p><p><font size=\"4\">Sports :</font></p><p>&nbsp;&nbsp;&nbsp; 1: Complete Cricket&nbsp; kit&nbsp;($100)&nbsp;&nbsp;&nbsp;"
		+"<input type=\"checkbox\" name=\"T1\" value=\"ON\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quantity<input type=\"text\" name=\"T2\" size=\"7\"></p>"
		+"<p>&nbsp;&nbsp;&nbsp; 2: Complete Soccer&nbsp; kit ($100)&nbsp;&nbsp;&nbsp;&nbsp;"
		+"<input type=\"checkbox\" name=\"T3\" value=\"ON\">&nbsp;&nbsp;&nbsp;&nbsp; Quantity"+"<input type=\"text\" name=\"T4\" size=\"7\"></p><p><font size=\"4\">Perfumes :</font></p><p>&nbsp;&nbsp;&nbsp; 1: Blue Jeans($50)<input type=\"checkbox\" name=\"T5\" value=\"ON\">&nbsp;&nbsp;&nbsp; Quantity<input type=\"text\" name=\"T6\" size=\"7\"></p><p>&nbsp;&nbsp;&nbsp; 2: Polo Sport($80)<input type=\"checkbox\" name=\"T7\" value=\"ON\">&nbsp;&nbsp;&nbsp;&nbsp;Quantity <input type=\"text\" name=\"T8\" size=\"7\"></p><p><font size=\"4\">Cigarettes :</font></p><p>&nbsp;&nbsp;&nbsp; 1: Marlboro($10)<input type=\"checkbox\" name=\"T9\" value=\"ON\">&nbsp;&nbsp;&nbsp;&nbsp;Quantity <input type=\"text\" name=\"T10\" size=\"7\"></p><p>&nbsp;&nbsp;&nbsp; 2: Dunhill($10)<input type=\"checkbox\" name=\"T11\" value=\"ON\">&nbsp;&nbsp;&nbsp;&nbsp;Quantity <input type=\"text\" name=\"T12\" size=\"7\"></p><blockquote>  <blockquote><blockquote><p><input type=\"submit\" value=\"Add to Cart\" name=\"B3\"></p>    </blockquote></blockquote></blockquote></form></body></html>");
	
		}
	}
}